local RankContentPlayerCell = app.mvc.createListViewCell(...)
local HeadRender = require("app.widget.renders.HeadRender")
local RankContentBaseRender = import(".RankContentBaseRender")

--data =
function RankContentPlayerCell.create(node)
    local sprite = RankContentPlayerCell.extend(node or cc.CSLoader:createNode(Res.RankPlayerCell))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init()
    return sprite
end

function RankContentPlayerCell:init(data)
    self.super.init(self, data)
    self:setContentSize( self._ui.Panel:getContentSize() )
    self._rankBaseRender = RankContentBaseRender.create(self._ui["Panel/baseRankCell"])
    self._headRender = HeadRender.create(self._ui["Panel/head"])
    self._headRender:setType(2)
    self._ui["Panel/tencentIcon"]:setVisible(false)

    self._ui["Panel/Button_1"]:addClickEventListener(function(sender)
        if self._data then
            self:dispatchCellEvent("lookPlayer", {userBaseInfo = self._data.userBaseInfo, pos = sender:convertToWorldSpaceAR(cc.p(0, 0))})
        end
    end)

end

function RankContentPlayerCell:refresh()
    if not self._data then
        return
    end
    local data = self._data
    self._rankBaseRender:setRank(data.rank)
    local isMy = false
    local userBaseInfo = data.userBaseInfo
    if userBaseInfo then
        self._headRender:setData(userBaseInfo)
        isMy = userBaseInfo.uid == UD.player.uid
    end
    self._rankBaseRender:setIsMy(isMy)

    if data.value11 then
        self._ui["Panel/value1"]:setPositionY(59)
        self._ui["Panel/value11"]:setString(data.value11)
    else
        self._ui["Panel/value1"]:setPositionY(47)
        self._ui["Panel/value11"]:setString("")
    end

    self._ui["Panel/value1"]:setString(data.value1)
    self._ui["Panel/value2"]:setString(data.value2)
    self._ui["Panel/value3"]:setString(data.value3)
    self._ui["Panel/Button_1"]:setVisible(data.isShowBtn == true)
end


return RankContentPlayerCell